/*!\file  main.c  The main kernel file.
 *
 *      This file is part of the micro-rtos package.
 *
 *  Copyright (c) 2008-2009 by 
		Gabriel Zabusek <gabriel.zabusek@gmail.com>
 *
 *      This program is free software; you can redistribute it and/or
 *      modify it under the terms of the GNU General Public License
 *      as published by the Free Software Foundation; either version
 *      2 of the License, or (at your option) any later version.
 */

#include <kernel/main.h>
#include <drivers/lcd/ZT018/ZT018.h>
#include <kernel/interrupt.h>
#include <kernel/task.h>
#include <kernel/critical.h>
#include <kernel/sched.h>
#include <include/std_io.h>
#include <include/types.h>
#include <boot/lpc2103.h>



void * task1_proc(void *d);
void * task2_proc(void *d);
void * task3_proc(void *d);

void *
def_link(void *d)
{
	printk("def link\n");
	while(1)
		printk(".");
	return NULL;
}

void *
task1_proc(void *d)
{
	//printk("T1 ahoj\n");

	while(1){
		printk("*");	
	}	

	return NULL;
}

void *
task2_proc(void *d)
{
	//printk("T2 ahoj\n");
	while(1)
		printk("+");

	return NULL;
}

void *
task3_proc(void *d)
{
	//printk("T3 ahoj\n");
	while(1)
		printk("-");

	return NULL;
}


int 
main(int argc, char ** argv)
{

	LCD_I2C0Init();
	LCD_Clear_Screen( 0xFFFF );

	IODIR |= (1<<17);

	task_t task1, task2, task3;
	task_create( &task1, task1_proc );
	task_create( &task2, task2_proc );
	task_create( &task3, task3_proc );

	printk("Magic starting\n");


	//bSchedulingStart = TRUE;
	//bFirstRestore = FALSE;

	//printk("Magic done\n");

	pCurTaskStackTop = task1.pStackTop + 16;//16 is the current context size - 15regs and spsr
	pCurRunningTask  = &task1;
	RestoreContext( task1.pStackTop ); 	//from this point on irqs are enabled


	//we should never get here!
	while(1)
	{
		printk("_");

	}


	return 0;
}
